/*=========================================================================
 Copyright (c) 2008, Nokia Corporation and/or its subsidiary(-ies).
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
 
     * Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.
     * Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.
     * Neither the name of the Nokia Corporation and/or its subsidiary(-ies)nor the
       names of its contributors may be used to endorse or promote products
       derived from this software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=========================================================================================*/

#ifndef _ncvImageStatistics_H
#define _ncvImageStatistics_H

#include "ncvImage.h"
#include <e32std.h>

/**
 * \typedef THistogram
 * \brief THistogram type definition for a TFixedArray that holds 256 TInts.
 * \note Symbian TClass.
 */
typedef TFixedArray<TInt,256> THistogram;


/**
 * \class CImageStatistics
 * \brief A class for calculating various statistics from CNokiaCVImages
 *
 * CImageStatistics provides the following statistical functions for CNokiaCVImages:
 *		- Histogram
 *		- Mean
 *		- Standard deviation
 *		- Image moments:
 *			- m00
 *			- m01
 *			- m10
 *			- m11
 *			- m20
 *			- m02
 *
 * Usage:
 * <pre>
 *	TReal mean;
 *	CImageStatistics::Mean(*iSourceBitmap, mean, (TChannel)aChannel);
 * </pre>
 */
class CImageStatistics
	{
public:
	/**
	 * \brief Calculate the histogram from a CNokiaCVImage.
	 * \param aImage CNokiaCVImage to use for calculation.
	 * \param aArray a TFixedArray to hold the histogram values.
	 * \param aChannel TChannel to use for calculation. Supports only EGrayChannel, ERedChannel, EGreenChannel and EBlueChannel NOT EAllChannels i.e. 256 values in the histogram only.
	 * \note the function can leave
	 */
	IMPORT_C static void Histogram( CNokiaCVImage& aImage, THistogram& aArray, TChannel aChannel = EGrayChannel );

	/**
	 * \brief Calculate the mean of CNokiaCVImage
	 * \param aImage CNokiaCVImage to use for calculation
	 * \param aMean The mean is stored here.
	 * \param aChannel TChannel to use for calculation.
	 * \note the function can leave
	 */
	IMPORT_C static void Mean( CNokiaCVImage& aImage, TReal& aMean, TChannel aChannel = EAllChannels);

	/**
	 * \brief Calculate the standard deviation of a CNokiaCVImage.
	 *
	 * Calculates the standard deviation of a channel in a CNokiaCVImage.  Calculates the mean as well.
	 *
	 * \param aImage CNokiaCVImage to use for calculation
	 * \param aStDev The standard deviation is stored here.
	 * \param aMean The mean is stored here.
	 * \param aChannel TChannel to use for calculation.
	 *
	 * \note the function can leave
	 */
	IMPORT_C static void StDev( CNokiaCVImage& aImage, TReal& aStDev, TReal& aMean, TChannel aChannel );

	/**
	 * \brief Calculate an image moment of CNokiaCVImage
	 *
	 * Calculates image moments from a CNokiaCVImage.
	 *	Possible moment xy-combinations are:
	 *	- 00
	 *	- 01
	 * 	- 10
	 *	- 11
	 *	- 20
	 *	- 02
	 *
	 * \param aImage CNokiaCVImage to use for calculation
	 * \param aXMoment 0,1 or 2.
	 * \param aYMoment 0,1 or 2.
	 * \param aChannel TChannel to use for calculation.
	 *
	 * \note the function can leave
	 */
	IMPORT_C static TUint32 Moment( CNokiaCVImage& aImage, TInt aXMoment, TInt aYMoment, TChannel aChannel = EAllChannels);
	};

#endif
